package com.hafu.dao;

import com.hafu.model.KuCun;
import com.hafu.util.DbUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class KuCunDao {
    public ArrayList<KuCun> getKuCunList(){
        ArrayList<KuCun> list = new ArrayList<>();
        //获取连接
        Connection conn = DbUtil.getConn();
        //获取sql
        String sql = "select * from kuCun";
        try {
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            ResultSet resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
                int id = resultSet.getInt("id");
                String spname = resultSet.getString("spname");
                int num = resultSet.getInt("num");
                KuCun kuCun1 = new KuCun(id,spname,num);
                list.add(kuCun1);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }
}
